package com.fenghongzhang.kuaishou.index.mine;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioButton;

import com.blankj.utilcode.util.SizeUtils;
import com.fenghongzhang.kuaishou.R;
import com.google.android.material.appbar.AppBarLayout;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener;

/**
 * 我的  页面
 */
public class MineFragment extends Fragment {

    private SmartRefreshLayout mRefreshLayout;
    private ImageView mBgTopIv;
    private AppBarLayout mAppBarLayout;
    private View view;
    private RadioButton rb1;
    private RadioButton rb2;
    private RadioButton rb3;
    private RadioButton rb4;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
        view=inflater.inflate(R.layout.fragment_mine, container, false);

        mRefreshLayout = view.findViewById(R.id.fragment_mine_refresh_layout);
        mBgTopIv = view.findViewById(R.id.fragment_mine_bg_iv);
        mAppBarLayout = view.findViewById(R.id.fragment_mine_app_bar);
        rb1=view.findViewById(R.id.rb1);
        rb2=view.findViewById(R.id.rb2);
        rb3=view.findViewById(R.id.rb3);
        rb4=view.findViewById(R.id.rb4);


        initTopStyle();
        return view;
    }
    private void initTopStyle() {
        //刷新框架监听
        mRefreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {
            @Override
            public void onHeaderMoving(RefreshHeader header, boolean isDragging, float percent, int offset, int headerHeight, int maxDragHeight) {
                mBgTopIv.setScaleX(1 + (float) (percent * 0.3));
                mBgTopIv.setScaleY(1 + (float) (percent * 0.3));
            }
        });
        //AppBarLayout滑动监听
        mAppBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                if (verticalOffset < 0 && verticalOffset > -SizeUtils.dp2px(200)) {
                    //响应区间
                    mBgTopIv.setTranslationY((float) (verticalOffset * 0.3));
                }
            }
        });

    }
}
